//
//  HomePageDetailFooterView.m
//  ShowYork
//
//  Created by hxh on 2020/10/4.
//  Copyright © 2020 hxh. All rights reserved.
//


#define HEADHEIGHT 74.0f
#define TOOLHEIGHT 46.0f
#define PROGRESSHEIGHT 28.0f
#define TAGHEIGHT 34.0f
#import "HomePageDetailFooterView.h"
#import "ZFSliderView.h"
#import "UILabel+Vertical.h"

typedef void(^doneBlock)(XHFooterType type);

@interface HomePageDetailFooterView ()<ZFSliderViewDelegate>
/// 基本信息视图
@property (nonatomic,strong)UIView *headView;
/// 工具栏视图
@property (nonatomic,strong)UIView *toolView;
/// 进度条视图
@property (nonatomic,strong)UIView *progressView;
/// 内容正文视图
@property (nonatomic,strong)UIView *contentView;
/// tag标签视图
@property (nonatomic,strong)UIView *tagToolView;
@property (nonatomic,strong)UIView *tagView;
@property (nonatomic,strong)UIImageView *tagImgView;
@property (nonatomic,strong)UILabel *tagLb;

@property (nonatomic,strong)UILabel *contentLb;
@property (nonatomic,strong)UIImageView *headerIcon;
@property (nonatomic,strong)UILabel *dissCount;
@property (nonatomic,strong)UILabel *likeCount;
@property (nonatomic,strong)UILabel *commentCount;
@property (nonatomic,strong)UIImageView *dissIcon;
@property (nonatomic,strong)UIImageView *likeIcon;
@property (nonatomic,strong)UIImageView *commentIcon;
@property (nonatomic,strong)UILabel *nameLb;
@property (nonatomic,strong)UILabel *subTitleLb;
@property (nonatomic,strong)UILabel *allLb;
@property (nonatomic,strong)UILabel *closeLb;
@property (nonatomic,strong)UITextView *textView;
@property (nonatomic,strong)CAGradientLayer *gradientLayer;

@property (nonatomic,strong)UIButton *followBtn;

@property (nonatomic,copy)doneBlock done;

@property (nonatomic,strong)HomePageItemModel *currentModel;

@property (nonatomic,strong)ZFSliderView *progress;

@property (nonatomic,weak)id<HomePageDetailFooterViewDelegate>delegate;

@property (nonatomic,strong)UIButton *commentBtn;
@property (nonatomic,strong)UIButton *dissBtn;
@property (nonatomic,strong)UIButton *likeBtn;
@property (nonatomic,strong)UIButton *contentBtn;

@property (nonatomic,assign)BOOL isMoreContent;

@end

@implementation HomePageDetailFooterView




- (instancetype)initWithCompleteBlock:(void (^)(XHFooterType type))completeBlock{
    if (self = [super init]) {
        [self setUI];
        
        if (completeBlock) {
            self.done = ^(XHFooterType type) {
                completeBlock(type);
            };
        }
    }
    return self;
}

- (void)setUI{
    
    // 设置文字最大高度
    CGFloat contentHeight = [self heightOfLines:2 font:font(14)];
    
    self.frame = CGRectMake(0,kScreenH, kScreenW, TOOLHEIGHT + HEADHEIGHT + TAGHEIGHT + PROGRESSHEIGHT + contentHeight + 12.0f);
    
    self.cl_y = kScreenH - self.cl_height;
    
    self.headView = [[UIView alloc]init];
    [self addSubview:self.headView];
    
    self.toolView = [[UIView alloc]init];
    [self addSubview:self.toolView];
    
    self.contentView = [[UIView alloc]init];
    [self addSubview:self.contentView];
    
    
    self.progressView = [[UIView alloc]init];
    [self addSubview:self.progressView];
    
    self.tagToolView = [[UIView alloc]init];
    [self addSubview:self.tagToolView];

    [self.toolView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.bottom.equalTo(self).offset(-GK_SAVEAREA_BTM);
        make.height.mas_equalTo(TOOLHEIGHT);
    }];
    
    self.likeCount = [[UILabel alloc]init];
    self.likeCount.textColor = [UIColor whiteColor];
    self.likeCount.font = font(14);
    [self.toolView addSubview:self.likeCount];

    [self.likeCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.toolView).offset(-16);
        make.right.equalTo(self.toolView.mas_right).offset(-16);
    
    }];

    self.likeIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"home_detail_like_tag"]];
    self.likeIcon.highlightedImage = [UIImage imageNamed:@"home_detail_like_select_tag"];
    [self.toolView addSubview:self.likeIcon];
    [self.likeIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.likeCount);
        make.right.equalTo(self.likeCount.mas_left).offset(-8);
    }];
    
    self.likeBtn = [[UIButton alloc]init];
    [self.likeBtn addTarget:self action:@selector(likeMethod) forControlEvents:UIControlEventTouchUpInside];
    [self.toolView addSubview:self.likeBtn];
    
    [self.likeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.likeIcon.mas_bottom).offset(5);
        make.top.equalTo(self.likeIcon.mas_top).offset(-5);
        make.left.equalTo(self.likeIcon.mas_left);
        make.right.equalTo(self.likeCount.mas_right);
    }];
    [self.likeIcon setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal | UILayoutConstraintAxisVertical];
    
    self.dissCount = [[UILabel alloc]init];
    self.dissCount.textColor = [UIColor whiteColor];
    self.dissCount.font = font(14);
    [self.toolView addSubview:self.dissCount];
    [self.dissCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.likeCount);
        make.right.equalTo(self.likeIcon.mas_left).offset(-16);
    }];

    self.dissIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"home_detail_diss_tag"]];
    self.dissIcon.highlightedImage = [UIImage imageNamed:@"home_detail_diss_select_tag"];
    [self.toolView addSubview:self.dissIcon];
    [self.dissIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.likeCount);
        make.right.equalTo(self.dissCount.mas_left).offset(-8);
    }];
    
    self.dissBtn = [[UIButton alloc]init];
    [self.dissBtn addTarget:self action:@selector(dissMethod) forControlEvents:UIControlEventTouchUpInside];
    [self.toolView addSubview:self.dissBtn];
   
    [self.dissBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.dissIcon.mas_bottom).offset(5);
        make.top.equalTo(self.dissIcon.mas_top).offset(-5);
        make.left.equalTo(self.dissIcon.mas_left);
        make.right.equalTo(self.dissCount.mas_right);
    }];
    [self.dissIcon setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal | UILayoutConstraintAxisVertical];
    
    
    self.commentCount = [[UILabel alloc]init];
    self.commentCount.textColor = [UIColor whiteColor];
    self.commentCount.font = font(14);
    [self.toolView addSubview:self.commentCount];
    [self.commentCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.likeCount);
        make.right.equalTo(self.dissIcon.mas_left).offset(-16);
    }];

    self.commentIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"home_detail_comment_tag"]];
    [self.toolView addSubview:self.commentIcon];
    [self.commentIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.likeCount);
        make.right.equalTo(self.commentCount.mas_left).offset(-8);
    }];

    self.commentBtn = [[UIButton alloc]init];
    [self.commentBtn addTarget:self action:@selector(showCommentMethod) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.commentBtn];
 
    [self.commentBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.commentIcon.mas_bottom).offset(5);
        make.top.equalTo(self.commentIcon.mas_top).offset(-5);
        make.left.equalTo(self.commentIcon.mas_left);
        make.right.equalTo(self.commentCount.mas_right);
       
    }];
    
    [self.commentIcon setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal | UILayoutConstraintAxisVertical];
    
    
    [self.progressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.toolView.mas_top);
        make.left.right.equalTo(self);
        make.height.mas_equalTo(PROGRESSHEIGHT);
    }];
    
    
    self.progress = [[ZFSliderView alloc]init];
    [self.progress setBackgroundImage:[UIImage imageNamed:@"ZFPlayer_slider"] forState:UIControlStateNormal];
    self.progress.thumbSize = CGSizeMake(6, 6);
    self.progress.sliderHeight = 1;
    self.progress.animate = NO;
    self.progress.allowTapped = NO;
    self.progress.isHideSliderButton = YES;
    self.progress.delegate = self;
    [self.progressView addSubview:self.progress];
    
    self.progress.minimumTrackTintColor = [UIColor whiteColor];
    self.progress.maximumTrackTintColor = C102;
    
    [self.progress mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.progressView);
        make.left.equalTo(self.progressView).offset(16);
        make.right.equalTo(self.progressView).offset(-16);
    }];
    
    [self.tagToolView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.progressView.mas_top);
        make.left.right.equalTo(self);
        make.height.mas_equalTo(TAGHEIGHT);
    }];
   
    self.tagView = [[UIView alloc]init];
    self.tagView.backgroundColor = RGBA(255, 255, 255, 0.5);
    self.tagView.layer.cornerRadius = 11;
    self.tagView.layer.masksToBounds = YES;
    [self.tagToolView addSubview:self.tagView];
    [self.tagView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.tagToolView).offset(16);
        make.bottom.equalTo(self.tagToolView).offset(-12);
        make.height.mas_equalTo(22);
    }];
    self.tagImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"home_page_#_tag"]];
    [self.tagView addSubview:self.tagImgView];
    
    // 新增
    self.tagLb = [[UILabel alloc]init];
    self.tagLb.textColor = UIColor.whiteColor;
    self.tagLb.font = font(12);
    self.tagLb.text = @"# 话题";
    [self.tagView addSubview:self.tagLb];
    
    [self.tagImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.tagView);
        make.left.equalTo(self.tagView).offset(12);
    }];
    
    [self.tagLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.tagView);
        make.left.equalTo(self.tagImgView.mas_right).offset(4);
        make.right.equalTo(self.tagView.mas_right).offset(-12);
    }];
    
    
    
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.tagToolView.mas_top).offset(-12);
        make.left.right.equalTo(self);
        make.height.mas_equalTo(contentHeight);
    }];
    

    self.contentLb = [[UILabel alloc]init];
    self.contentLb.text = @"高考可能是一个人一生中最为难忘的记忆之一";
    self.contentLb.textColor = [UIColor whiteColor];
    self.contentLb.font = font(14);
    self.contentLb.numberOfLines = 2;
    [self.contentView addSubview:self.contentLb];
    
    self.headerIcon = [[UIImageView alloc]init];
    self.headerIcon.layer.cornerRadius = 19;
    self.headerIcon.layer.masksToBounds = YES;
    self.headerIcon.image = [UIImage imageNamed:@"defaut_header"];
    [self.headView addSubview:self.headerIcon];

    
    self.textView = [[UITextView alloc]init];
    self.textView.font = font(14);
    self.textView.textColor = [UIColor whiteColor];
    self.textView.backgroundColor = [UIColor clearColor];
    self.textView.showsVerticalScrollIndicator = NO;
    self.textView.showsHorizontalScrollIndicator = NO;
    self.textView.textContainerInset = UIEdgeInsetsZero;
    self.textView.textContainer.lineFragmentPadding = 0;
    self.textView.editable  = NO;
    [self.contentView addSubview:self.textView];
    [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.equalTo(self.contentLb);
        make.right.equalTo(self).offset(-16);
    }];
    
    self.allLb = [[UILabel alloc]init];
    self.allLb.text = @"展开";
    self.allLb.textColor = [UIColor whiteColor];
    self.allLb.font = font(14);
    self.allLb.userInteractionEnabled = YES;
    [self addSubview:self.allLb];
    [self.allLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentLb.mas_bottom);
        make.left.equalTo(self.contentLb.mas_right);
    }];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapMethod)];
    [self.allLb addGestureRecognizer:tap];
    
    [self.contentLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(16);
        make.right.equalTo(self).offset(-60);
        make.top.equalTo(self.contentView);
        make.height.mas_equalTo(contentHeight);
    }];

    [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.bottom.equalTo(self.contentView.mas_top);
        make.height.mas_equalTo(HEADHEIGHT);
    }];
    
    [self.headerIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(38, 38));
        make.left.equalTo(self.headView).offset(16);
        make.bottom.equalTo(self.headView).offset(-12);
    }];
  

    self.nameLb = [[UILabel alloc]init];
    self.nameLb.text = @"Charlene";
    self.nameLb.textColor = [UIColor whiteColor];
    self.nameLb.font = [UIFont boldSystemFontOfSize:14];
    [self.headView addSubview:self.nameLb];
    
    self.subTitleLb = [[UILabel alloc]init];
    self.subTitleLb.textColor = RGBA(204, 204, 204, 1);
    self.subTitleLb.font = [UIFont boldSystemFontOfSize:14];
    self.subTitleLb.text = @"2019-12-12";
    self.subTitleLb.textAlignment = NSTextAlignmentLeft;
    [self.headView addSubview:self.subTitleLb];
    
    self.followBtn = [[UIButton alloc]init];
    [self.followBtn setTitle:@"+ 关注" forState:UIControlStateNormal];
    [self.followBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.followBtn.titleLabel.font = font(14);
    [self.followBtn setBackgroundImage:[UIImage imageNamed:@"social_confirm_tag"] forState:UIControlStateNormal];
    [self.followBtn setBackgroundImage:[UIImage imageNamed:@"social_confirm_tag"] forState:UIControlStateHighlighted];
    [self.followBtn addTarget:self action:@selector(followMethod) forControlEvents:UIControlEventTouchUpInside];
    [self.headView addSubview:self.followBtn];
    
    [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerIcon.mas_right).offset(8);
        make.bottom.equalTo(self.headView).offset(-21);
        make.right.equalTo(self.subTitleLb.mas_left).offset(-4);
        make.height.mas_equalTo(20);
    }];
    
    [self.subTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.headView).offset(-21);
        make.left.equalTo(self.nameLb.mas_right).offset(4);
        make.right.equalTo(self.followBtn.mas_left).offset(-12);
        make.width.mas_greaterThanOrEqualTo(60);
        make.height.mas_equalTo(20);
    }];
    
    self.closeLb = [[UILabel alloc]init];
    self.closeLb.text = @"收起";
    self.closeLb.textColor = [UIColor whiteColor];
    self.closeLb.textAlignment = NSTextAlignmentRight;
    self.closeLb.font = font(14);
    self.closeLb.userInteractionEnabled = YES;
    self.closeLb.hidden = YES;
    [self.tagToolView addSubview:self.closeLb];
    [self.closeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.tagToolView).offset(8);
        make.right.equalTo(self.tagToolView).offset(-16);
        make.size.mas_equalTo(CGSizeMake(40, 20));
    }];
    
    UITapGestureRecognizer *closeTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(closeMethod)];
    [self.closeLb addGestureRecognizer:closeTap];
    

    [self.followBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.headerIcon.mas_bottom).offset(-6);
        make.right.equalTo(self.headView).offset(-16);
        make.size.mas_equalTo(CGSizeMake(60, 26));
    }];
    
    self.hidden = YES;
    
    self.headerIcon.userInteractionEnabled = YES;
    UITapGestureRecognizer *userInfoTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showUserInfoMethod)];
    [self.headerIcon addGestureRecognizer:userInfoTap];
    
    self.nameLb.userInteractionEnabled = YES;
    UITapGestureRecognizer *nameTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showUserInfoMethod)];
    [self.nameLb addGestureRecognizer:nameTap];
    
    self.tagView.userInteractionEnabled = YES;
    UITapGestureRecognizer *topicTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showTopicMethod)];
    [self.tagView addGestureRecognizer:topicTap];
    
    
//    self.contentBtn = [[UIButton alloc]init];
//    [self.contentBtn addTarget:self action:@selector(contentShow) forControlEvents:UIControlEventTouchUpInside];
//    [self.contentView addSubview:self.contentBtn];
//    [self.contentBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.left.right.bottom.equalTo(self.contentView);
//    }];
    
    UITapGestureRecognizer *textViewTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(contentShow)];
    [self.textView addGestureRecognizer:textViewTap];
   
    UITapGestureRecognizer *contentTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(contentShow)];
    [self.contentView addGestureRecognizer:contentTap];
   
    self.gradientLayer = [CAGradientLayer layer];
    self.gradientLayer.hidden = YES;
    self.gradientLayer.colors = @[(id)RGBA(0, 0, 0, 0).CGColor,(id)RGBA(0, 0, 0, 0.3).CGColor,(id)RGBA(0, 0, 0,0.6).CGColor];
    [self.layer insertSublayer:self.gradientLayer atIndex:0];

}

- (void)showInView:(UIView *)mainView delegate:(nonnull id<HomePageDetailFooterViewDelegate>)delegate{
    self.delegate = delegate;
    [mainView addSubview:self];
}

- (void)likeMethod{
    
    if ([RPAppManager isShowNetworkView]) {
        [WHToast showErrorWithMessage:@"网络好像有点问题，请检查后重试" duration:2 finishHandler:nil];
        return;
    }
    if (![RPAppManager isLogin]) {
        self.done(XHFOOTERLIKE);
        return;
    }
    self.currentModel.isLike = !self.currentModel.isLike;
    self.likeIcon.highlighted = self.currentModel.isLike;
    NSInteger max = self.currentModel.likeNum.intValue +  (self.currentModel.isLike?1:-1);
    if (max >= 10000) {
        NSInteger count = max;
        if (count % 1000 == 0) {
            count += 1;
        }
        self.likeCount.text = [NSString stringWithFormat:@"%@w",[RPAppManager notRounding:count/10000.0f afterPoint:1]];
    }else{
        self.likeCount.text = [NSString stringWithFormat:@"%ld",(long)max];
    }
    self.currentModel.likeNum = @(max);
    self.done(XHFOOTERLIKE);
    [MobClick event:@"homeDetail_like"];
}
- (void)dissMethod{
    if ([RPAppManager isShowNetworkView]) {
        [WHToast showErrorWithMessage:@"网络好像有点问题，请检查后重试" duration:2 finishHandler:nil];
        return;
    }
    if (![RPAppManager isLogin]) {
        self.done(XHFOOTERDISS);
        return;
    }
    self.currentModel.isUnLike = !self.currentModel.isUnLike;
    self.dissIcon.highlighted = self.currentModel.isUnLike;
    NSInteger max = self.currentModel.unlikeNum.intValue + (self.currentModel.isUnLike?1:-1);
    if (max >= 10000) {
        NSInteger count = max;
        if (count % 1000 == 0) {
            count += 1;
        }
        self.dissCount.text = [NSString stringWithFormat:@"%@w",[RPAppManager notRounding:count/10000.0f afterPoint:1]];
    }else{
        self.dissCount.text = [NSString stringWithFormat:@"%ld",(long)max];
    }
    self.currentModel.unlikeNum = @(max);
    self.done(XHFOOTERDISS);
    [MobClick event:@"homeDetail_unLike"];
    

}

- (void)contentShow{
    
    if (self.currentModel.isShowAllContent) {
        [self showNormalWithAnimate:YES];
    }else{
        if (self.allLb.text.length != 0) {
            [self showAllWithAnimate:YES];
        }
    }
}

- (void)followMethod{
    self.done(XHFOOTERFOLLOW);
}

- (void)closeMethod{
    [self showNormalWithAnimate:YES];
}
- (void)showUserInfoMethod{
    self.done(XHFOOTERYUSER);
}
- (void)showCommentMethod{
    self.done(XHFOOTERCOMMENT);
}

- (void)showTopicMethod{
    self.done(XHFOOTERTOPIC);
}

- (void)tapMethod{
    [MobClick event:@"homeDetail_expand_click"];
    [self showAllWithAnimate:YES];
}

- (CGFloat)heightOfLines:(int)lines font:(UIFont *)font{
    if (lines <= 0) {
        return 0;
    }
    NSString *str = @"*";
    for (int index = 0; index < lines - 1 ; index++) {
        str = [str stringByAppendingString:@"\n*"];
    }
    NSDictionary *dict = @{NSFontAttributeName:font};
    CGSize size = [str sizeWithAttributes:dict];
    return ceil(size.height);
}

- (void)resetProgress{

    self.progress.value = 0.0;
    
    [self.progress stopForward];
    
    self.progress.sliderHeight = 1;
    
    self.progress.isHideSliderButton = YES;
    
}

- (void)setProgressValue:(CGFloat)progressValue{
    
    if (self.progress.isdragging) {
        return;
    }

    if (progressValue == 0) {
        [self.progress stopForward];
    }else{
        [self.progress startForward];
    }
    
    _progressValue = progressValue;
    
    self.progress.value = progressValue;
    
}

- (void)show{
    [self showNormalWithAnimate:YES];
    self.hidden = NO;
}

- (void)hide{
    [UIView animateWithDuration:0.25 animations:^{
        self.cl_y = kScreenH;
    } completion:^(BOOL finished) {
        if (finished) {
            self.hidden = YES;
        }
    }];
}
- (void)setItemModel:(HomePageItemModel *)itemModel animate:(BOOL)animate{
 
    self.currentModel = itemModel;
    self.contentLb.text = itemModel.contentText;
    CGFloat maxH = [self heightOfLines:2 font:font(14)];
    CGSize size = [RPAppManager getTextSizeWithText:self.contentLb.text font:font(14) maxSize:CGSizeMake(kScreenW - 16 - 60, MAXFLOAT)];
    self.isMoreContent = !(maxH >= ceil(size.height));
    self.allLb.text = (maxH >= ceil(size.height))?@"":@"展开";    // 判断是否展示底部视图
    if (itemModel.showFooterTool) {
        self.hidden = NO;
        itemModel.isShowAllContent?[self showAllWithAnimate:NO]:[self showNormalWithAnimate:NO];
    }else{
        [self hide];
    }
    // 判断是否是作品
    if (![itemModel.type isEqualToString:@"2"] && itemModel.tag != nil) {
        self.tagLb.text = itemModel.tag.tagName;
        self.tagView.hidden = NO;
    }else{
        self.tagLb.text = @"";
        self.tagView.hidden = YES;
    }
    

    self.nameLb.text = itemModel.realName;
    self.dissCount.text = itemModel.unlikeNum.stringValue;
    self.likeCount.text = itemModel.likeNum.stringValue;
    if (self.currentModel.readyPlay) {
        [self.progress stopForward];
    }else{
        [self.progress startForward];
    }
    if (itemModel.showUserInfo) {
        if ([RPAppManager getCustomerId] && [itemModel.userId isEqualToNumber:[RPAppManager getCustomerId]]) {
            self.followBtn.hidden = YES;
        }else{
            if (itemModel.followType.intValue == 3 || itemModel.followType.intValue == 1) {
                self.followBtn.hidden = YES;
            }else if (itemModel.followType.intValue == 2){
                self.followBtn.hidden = NO;
                [self.followBtn setTitle:@"+ 回关" forState:UIControlStateNormal];
            }else{
                self.followBtn.hidden = NO;
                [self.followBtn setTitle:@"+ 关注" forState:UIControlStateNormal];
            }
        }
    }else{
        self.followBtn.hidden = YES;
    }
    if (itemModel.likeNum.intValue >= 10000) {
        NSInteger count = itemModel.likeNum.intValue;
        if (count % 1000 == 0) {
            count += 1;
        }
        self.likeCount.text = [NSString stringWithFormat:@"%@w",[RPAppManager notRounding:count/10000.0f afterPoint:1]];
    }else{
        self.likeCount.text = [NSString stringWithFormat:@"%@",itemModel.likeNum];
    }
    if (itemModel.unlikeNum.intValue >= 10000) {
        NSInteger count = itemModel.unlikeNum.intValue;
        if (count % 1000 == 0) {
            count += 1;
        }
        self.dissCount.text = [NSString stringWithFormat:@"%@w",[RPAppManager notRounding:count/10000.0f afterPoint:1]];
    }else{
        self.dissCount.text = [NSString stringWithFormat:@"%@",itemModel.unlikeNum];
    }

    
    if (itemModel.commentNum.intValue >= 10000) {
        NSInteger count = itemModel.commentNum.intValue;
        if (count % 1000 == 0) {
            count += 1;
        }
        self.commentCount.text = [NSString stringWithFormat:@"%@w",[RPAppManager notRounding:count/10000.0f afterPoint:1]];
    }else{
        self.commentCount.text = [NSString stringWithFormat:@"%@",itemModel.commentNum.intValue == 0?@0:itemModel.commentNum];
    }
    
    self.likeIcon.highlighted = itemModel.isLike;
    self.dissIcon.highlighted = itemModel.isUnLike;

    self.progress.hidden = itemModel.contentType.intValue != 3;
    
    if ([itemModel.userId isEqualToNumber:[RPAppManager getCustomerId]]) {
        UserInfoModel *userInfo = [UserInfoModel userInfo];
        if (userInfo.imagePath.length == 0) {
            if (userInfo.sex.intValue == 0) {
                self.headerIcon.image = [UIImage imageNamed:@"defaut_header"];
            }else if (userInfo.sex.intValue == 1){
                self.headerIcon.image = [UIImage imageNamed:@"common_boy_tag"];
            }else{
                self.headerIcon.image = [UIImage imageNamed:@"common_girl_tag"];
            }
        }else{
            [self.headerIcon sd_setImageWithURL:[NSURL URLWithString:userInfo.imagePath] placeholderImage:[UIImage imageNamed:@"defaut_header"]];
        }
    }else{
        if (itemModel.imagePath.length == 0) {
            if (itemModel.sex.intValue == 0) {
                self.headerIcon.image = [UIImage imageNamed:@"defaut_header"];
            }else if (itemModel.sex.intValue == 1){
                self.headerIcon.image = [UIImage imageNamed:@"common_boy_tag"];
            }else{
                self.headerIcon.image = [UIImage imageNamed:@"common_girl_tag"];
            }
        }else{
            [self.headerIcon sd_setImageWithURL:[NSURL URLWithString:itemModel.imagePath] placeholderImage:[UIImage imageNamed:@"defaut_header"]];
        }
    }
//
    if (itemModel.showUserInfo) {
        self.subTitleLb.text = itemModel.showCreateTime?[NSString stringWithFormat:@"· %@",itemModel.createDetailTimeStr]:@"";
    }else{
        self.subTitleLb.text = itemModel.showCreateTime?[NSString stringWithFormat:@"%@",itemModel.createDetailTimeStr]:@"";
    }

    CGSize subTitleSize = [RPAppManager getTextSizeWithText:self.subTitleLb.text font:[UIFont boldSystemFontOfSize:14] maxSize:CGSizeMake(kScreenW, MAXFLOAT)];
    
    [self.subTitleLb mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_greaterThanOrEqualTo(ceil(subTitleSize.width));
    }];
    


    if (!itemModel.showUserInfo) {
        self.headerIcon.hidden = YES;
        self.nameLb.text = @"";
        [self.headerIcon mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(0);
            make.left.equalTo(self.headView);
        }];
        [self.nameLb mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.headerIcon.mas_right).offset(10);
        }];
    }else{
        self.headerIcon.hidden = NO;
        [self.headerIcon mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(38);
            make.left.equalTo(self.headView).offset(16);
        }];
        [self.nameLb mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.headerIcon.mas_right).offset(8);
        }];
    }
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissView)];
    [self addGestureRecognizer:tap];
    
    if ([[RPAppManager getCustomerId] isEqualToNumber:itemModel.userId]) {
        // 审核中 或者 已拒绝
        self.likeBtn.userInteractionEnabled = itemModel.isDisplay.intValue == 1;
        self.dissBtn.userInteractionEnabled = itemModel.isDisplay.intValue == 1;
        self.commentBtn.userInteractionEnabled = itemModel.isDisplay.intValue == 1;
        self.likeIcon.image = [UIImage imageNamed:itemModel.isDisplay.intValue == 1?@"home_detail_like_tag":@"home_unlike_tag"];
        self.dissIcon.image = [UIImage imageNamed:itemModel.isDisplay.intValue == 1?@"home_detail_diss_tag":@"home_undiss_tag"];
        self.commentIcon.image = [UIImage imageNamed:itemModel.isDisplay.intValue == 1?@"home_detail_comment_tag":@"home_uncomment_tag"];
        
        self.commentCount.textColor = itemModel.isDisplay.intValue == 1?UIColor.whiteColor:C102;
        self.dissCount.textColor = itemModel.isDisplay.intValue == 1?UIColor.whiteColor:C102;
        self.likeCount.textColor = itemModel.isDisplay.intValue == 1?UIColor.whiteColor:C102;
        
    }else{
        self.likeBtn.userInteractionEnabled = YES;
        self.dissBtn.userInteractionEnabled = YES;
        self.commentBtn.userInteractionEnabled = YES;
        
        self.likeIcon.image = [UIImage imageNamed:@"home_detail_like_tag"];
        self.dissIcon.image = [UIImage imageNamed:@"home_detail_diss_tag"];
        self.commentIcon.image = [UIImage imageNamed:@"home_detail_comment_tag"];
        
        self.commentCount.textColor = UIColor.whiteColor;
        self.dissCount.textColor = UIColor.whiteColor;
        self.likeCount.textColor = UIColor.whiteColor;
    }
    
}
- (void)dismissView{
    [self showNormalWithAnimate:YES];
}

- (void)showAllWithAnimate:(BOOL)animate{
    self.currentModel.isShowAllContent = YES;
    CGFloat progressHeight = self.currentModel.contentType.intValue == 3?28.0f:0;
    self.gradientLayer.hidden = YES;
    CGSize size = [RPAppManager getTextSizeWithText:self.contentLb.text font:font(14) maxSize:CGSizeMake(kScreenW - 32, MAXFLOAT)];
    self.contentLb.hidden = YES;
    self.allLb.hidden = YES;
    self.closeLb.hidden = NO;
    self.textView.hidden = NO;
    self.textView.text = self.contentLb.text;

    
    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
        [self.textView setContentOffset:CGPointZero];
    }];
    
    self.backgroundColor = RGBA(0, 0, 0, 0.7);

    self.cl_y = 0;
    
    self.cl_height = kScreenH;
    
    CGFloat tagHeight = 0;
    // 新增判断方法
    if ((self.currentModel.tag != nil && ![self.currentModel.type isEqualToString:@"2"]) || self.isMoreContent) {
        tagHeight = TAGHEIGHT;
    }
      
    [self layoutIfNeeded];
    
    CGFloat textH = MIN(ceil(size.height), kScreenH - kNavBarHeight - 64 - 200);
    CGFloat margin = self.contentLb.text.length == 0?0:-12;
    if (animate) {
        [UIView animateWithDuration:0.25 animations:^{
            [self.subTitleLb mas_updateConstraints:^(MASConstraintMaker *make) {
                make.bottom.equalTo(self.headView).offset(self.currentModel.showUserInfo?-21:-12);
            }];
            [self.contentView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(textH);
                make.bottom.equalTo(self.tagToolView.mas_top).offset(margin);
            }];
            [self.contentLb mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(textH);
            }];
            [self.progressView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(progressHeight);
            }];
            [self.tagToolView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(tagHeight);
            }];

            [self layoutIfNeeded];
            
        } completion:^(BOOL finished) {
        }];
    }else{
        [self.subTitleLb mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.headView).offset(self.currentModel.showUserInfo?-21:-12);
        }];
        [self.contentView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(textH);
            make.bottom.equalTo(self.tagToolView.mas_top).offset(margin);
        }];
        [self.contentLb mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(textH);
        }];
        [self.progressView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(progressHeight);
        }];
        [self.tagToolView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(tagHeight);
        }];
    }
    if (self.delegate && [self.delegate respondsToSelector:@selector(scrollViewEnable:)]) {
        [self.delegate scrollViewEnable:NO];
    }
    

}

- (void)showNormalWithAnimate:(BOOL)animate{
    self.closeLb.hidden = YES;
    self.currentModel.isShowAllContent = NO;
    self.backgroundColor = [UIColor clearColor];
    CGFloat progressHeight = 0;
    CGFloat tagHeight = 0;
    // 判断有没有有视频
    if(self.currentModel.contentType.intValue == 3){
        progressHeight = PROGRESSHEIGHT;
    }
    // 判断有没有tagView
    if ((self.currentModel.tag != nil && ![self.currentModel.type isEqualToString:@"2"])) {
        tagHeight = TAGHEIGHT;
    }
    CGSize size = [RPAppManager getTextSizeWithText:self.contentLb.text font:font(14) maxSize:CGSizeMake(kScreenW - 60 - 16, MAXFLOAT)];
    
    CGFloat maxH = [self heightOfLines:2 font:font(14)];
    
    CGFloat textH = 0;
    if (self.contentLb.text.length != 0) {
        textH = MIN(ceil(size.height),maxH);
    }
    CGFloat margin = self.contentLb.text.length == 0?0:-12;
    if (animate) {
        [UIView animateWithDuration:0.25 animations:^{
            [self.subTitleLb mas_updateConstraints:^(MASConstraintMaker *make) {
                make.bottom.equalTo(self.headView).offset(self.currentModel.showUserInfo?-21:-12);
            }];
            [self.contentView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(textH);
                make.bottom.equalTo(self.tagToolView.mas_top).offset(margin);
            }];
            [self.contentLb mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(textH);
            }];
            [self.progressView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(progressHeight);
            }];
            [self.tagToolView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(tagHeight);
            }];
            self.cl_y = kScreenH - (HEADHEIGHT + TOOLHEIGHT + GK_SAVEAREA_BTM + textH + progressHeight + tagHeight + fabs(margin));
            self.cl_height = HEADHEIGHT + TOOLHEIGHT + textH + GK_SAVEAREA_BTM + progressHeight + tagHeight + fabs(margin);

            [self layoutIfNeeded];
        } completion:^(BOOL finished) {
            if (finished) {
                self.textView.editable = NO;
                self.textView.hidden = YES;
                self.contentLb.hidden = NO;
                self.allLb.hidden = NO;
                self.textView.text = @"";
                self.gradientLayer.hidden = NO;
            }
        }];
    }else{
        
        [self.subTitleLb mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.headView).offset(self.currentModel.showUserInfo?-21:-12);
        }];
        
        [self.contentView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(textH);
            make.bottom.equalTo(self.tagToolView.mas_top).offset(margin);
        }];
        [self.contentLb mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(textH);
        }];
        [self.progressView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(progressHeight);
        }];
        [self.tagToolView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(tagHeight);
        }];
        
        self.cl_y = kScreenH - (HEADHEIGHT + TOOLHEIGHT + textH + progressHeight + tagHeight + GK_SAVEAREA_BTM + fabs(margin));
        self.cl_height = HEADHEIGHT + TOOLHEIGHT + textH + GK_SAVEAREA_BTM + progressHeight + tagHeight + fabs(margin);
       
        self.gradientLayer.hidden = NO;
    
        self.textView.hidden = YES;
        self.textView.editable = NO;
        self.contentLb.hidden = NO;
        self.allLb.hidden = NO;
        self.textView.text = @"";
     
    }
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(scrollViewEnable:)]) {
        [self.delegate scrollViewEnable:YES];
    }
}

- (void)drawRect:(CGRect)rect{
    [super drawRect:rect];
    if (!self.gradientLayer.hidden) {
        if (!self.currentModel.showUserInfo && self.currentModel.showCreateTime) {
            self.gradientLayer.frame = CGRectMake(0,24, kScreenW,self.cl_height - self.subTitleLb.cl_y + 24);
        }else{
            self.gradientLayer.frame = CGRectMake(0, 0, kScreenW, self.cl_height);
        }
    }
}

#pragma mark - ZFSliderViewDelegate
// 滑杆点击
- (void)sliderTapped:(float)value{

    if (self.delegate && [self.delegate respondsToSelector:@selector(updateVideoProgressValue:)]) {
        [self.delegate updateVideoProgressValue:value];
    }
}
// 滑块滑动开始
- (void)sliderTouchBegan:(float)value{
        
    self.progress.sliderHeight = 2;
    self.progress.isdragging = YES;
    self.progress.isHideSliderButton = NO;
    [self showNormalWithAnimate:YES];
   
    [UIView animateWithDuration:0.25 animations:^{
        self.headView.alpha = 0;
        self.contentView.alpha = 0;
        self.toolView.alpha = 0;
        self.tagView.alpha = 0;
        self.allLb.alpha = 0;
    }];
    
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(progressBeginDraging)]) {
        [self.delegate progressBeginDraging];
    }
    
}
// 滑块滑动中
- (void)sliderValueChanged:(float)value{
    if (self.delegate && [self.delegate respondsToSelector:@selector(changeVideoProgressValue:)]) {
        [self.delegate changeVideoProgressValue:value];
    }
}
// 滑块滑动结束
- (void)sliderTouchEnded:(float)value{
    
    self.progress.isdragging = NO;
        
    if (self.delegate && [self.delegate respondsToSelector:@selector(updateVideoProgressValue:)]) {
        [self.delegate updateVideoProgressValue:value];
    }

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        if (!self.progress.isdragging) {
            self.progress.sliderHeight = 1;
            self.progress.isHideSliderButton = YES;
        }
    });
    
    
    [UIView animateWithDuration:3 animations:^{

        self.headView.alpha = 1;
        self.contentView.alpha = 1;
        self.toolView.alpha = 1;
        self.tagView.alpha = 1;
        self.allLb.alpha = 1;
    }];
}





@end
